package com.love.labuladong.unionlist;

/**
 * @description: 洛谷版-并查集
 * @author: zh
 * @create: 2024-12-01 20:36
 **/
public class UnionFindListLouGu {


    public static int MAXN = 10001;

    public static int[] father = new int[MAXN];

    public static int n;

    public static void build(){

        for (int i = 0; i < n; i++) {
            father[i] = i;
        }
    }


    public static int find(int  i){
        if (i != father[i]){
            father[i] = find(father[i]);
        }
        return father[i];
    }

    public static boolean isSameSet(int x,int y){
        return find(x) == find(y);
    }


    public static void union(int x,int y){
        father[find(x)] = find(y);
    }




}
